/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2022并保留所有权利。
 * Copyright 2022, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.concurrent;


import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;


class TaskApplicationTests {
    //目标:炒菜
    //1.洗菜 5秒
    //2.买盐 3秒
    public static void main(String[] args) throws InterruptedException {
        Executor executor=Executors.newFixedThreadPool(2);
        CountDownLatch countDownLatch=new CountDownLatch(2);
        long now = System.currentTimeMillis();
        //洗菜5秒
        executor.execute(()->{
             try{
                 Thread.sleep(5000);

             }catch (Exception e){
                 e.printStackTrace();
             }finally {
                 if(countDownLatch!=null){
                     countDownLatch.countDown();
                 }
             }
        });
        //买盐3秒
        executor.execute(()->{
             try{
                 Thread.sleep(3000);
             }catch (Exception e){
                e.printStackTrace();
             }finally {
                 if(countDownLatch!=null){
                     countDownLatch.countDown();
                 }
             }
        });
        countDownLatch.await();
        System.out.println("可以炒菜了"+(System.currentTimeMillis()-now));
    }
}

